--- 2422 - id
--- Iron hammer maked by Kronos aka Hellboy ---
local craftable_table = {

	[5880] = { -- iron ore
		[1] = {newId = 2543, newType = 5, trashChance = 0, trashId = 2257, effect = CONST_ME_BLOCKHIT}, --- bolts
		[2] = {newId = 2403, newType = 1, trashChance = 0, trashId = 2257, desc = true, effect = CONST_ME_BLOCKHIT}, --- knife
		[3] = {newId = 2405, newType = 1, trashChance = 0, trashId = 2257, effect = CONST_ME_BLOCKHIT}, --- sickle
		[4] = {newId = 2406, newType = 1, trashChance = 10, trashId = 2257, effect = CONST_ME_BLOCKHIT}, --- short sword
		[10] = {newId = 5887, newType = 1, trashChance = 30, trashId = 2257, effect = CONST_ME_BLOCKHIT}, --- steel
		[14] = {newId = 2376, effect = CONST_ME_BLOCKHIT}, --- sword
		[15] = {newId = 2398, effect = CONST_ME_BLOCKHIT} --- mace
	},

	[5887] = { -- royal steel
		[10] = {newId = 2457, newType = 1, trashChance = 10, trashId = 2256, effect = CONST_ME_BLOCKHIT}, --- steel helmet
		[12] = {newId = 2647, newType = 1, trashChance = 20, trashId = 2256, effect = CONST_ME_BLOCKHIT}, --- plate legs
		[15] = {newId = 2509, newType = 1, trashChance = 5, trashId = 2256, effect = CONST_ME_BLOCKHIT}, --- steel shield
		[20] = {newId = 2463, newType = 1, trashChance = 25, trashId = 2256, effect = CONST_ME_BLOCKHIT}, --- plate armor
		[25] = {newId = 2513, newType = 1, trashChance = 15, trashId = 2256, effect = CONST_ME_BLOCKHIT} --- battle shield
	},

	[5888] = { -- hell steel
	},

	[5901] = { -- wood
		[1] = {newId = 2544, newType = 8, trashChance = 0, trashId = 2255, effect = CONST_ME_BLOCKHIT}, --- arrows
		[8] = {newId = 2512, newType = 1, trashChance = 0, trashId = 2255, effect = CONST_ME_BLOCKHIT} --- wooden shield
	},

	[5899] = { -- craftable_from_turtle_shell
		[10] = {newId = 6131, newType = 1, trashChance = 40, trashId = 0, effect = CONST_ME_BLOCKHIT} --- turtle shield
	}

}

	--- added

local recipe = {
	--- pick, stick + 5x iron ore
	{newId = 2553, components = {[7426] = 1, [5880] = 5}, effect = CONST_ME_BLOCKHIT},
	
	--- 2x royal spear, 2x spear + 10x iron ore
	{newId = 7378, newType = 2, components = {[2389] = 2, [5880] = 10}, effect = CONST_ME_BLOCKHIT},
	
	-- hand axe, stick + 3x iron ore
	{newId = 2380, components = {[7426] = 1, [5880] = 3}, effect = CONST_ME_BLOCKHIT},
	-- axe, stick + 13x iron ore
	{newId = 2553, components = {[7426] = 1, [5880] = 13}, effect = CONST_ME_BLOCKHIT}
}

	--- //
local specDescr = 'Item maked by |NAME|.'
	
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local percent = math.random(1, 100)
	
	if isInArray({1293, 1295}, itemEx.itemid) then --- stone [ok]
		if percent <= 25 then
			doTransformItem(itemEx.uid, 1294, math.random(3, 11))
			doSendMagicEffect(toPosition.x == CONTAINER_POSITION and getCreaturePosition(cid) or toPosition, CONST_ME_BLOCKHIT)
		else
			doSendMagicEffect(toPosition.x == CONTAINER_POSITION and getCreaturePosition(cid) or toPosition, CONST_ME_POFF)
		end
		return true
	end
	
	if toPosition.x == CONTAINER_POSITION then
		doPlayerSendDefaultCancel(cid, 0)
		return false
	end
	
	local tempTable, anvilOnPos, removeTable = {}, false, {}
	local CRAFTABLE_ITEMS = nil
	
	if getThingFromPos({x = toPosition.x, y = toPosition.y, z = toPosition.z, stackpos = toPosition.stackpos + 1}).itemid ~= 2555 then
		for ss = 1, 10 do
			local tempItem = getThingFromPos({x = toPosition.x, y = toPosition.y, z = toPosition.z, stackpos = ss})
			local table_count_info = tempTable[tempItem.itemid]
			if tempItem.uid == 0 then
				break
			end
			
			if tempItem.itemid == 2555 then
				anvilOnPos = true
				break
			end
			if hasProperty(tempItem.uid, CONST_PROP_MOVEABLE) then
				if tempItem.uid ~= itemEx.uid then
					table.insert(removeTable, tempItem.uid)
				end
				if table_count_info == nil then
					table.insert(tempTable, tempItem.itemid, (tempItem.type ~= 0 and tempItem.type or 1))
				else
					table.insert(tempTable, tempItem.itemid, table_count_info +(tempItem.type ~= 0 and tempItem.type or 1))
				end
			end
		end

		for _, table_c in pairs(recipe) do --- sam przepis
			if table.maxn(tempTable) == 0 then
				break
			end
			recipeMemory = true
			for id2, count2 in pairs(table_c.components) do --- kazdy element
				if tempTable[id2] == nil or tempTable[id2] ~= count2 then
					recipeMemory = false
					break
				end
			end
			
			if recipeMemory then
				for m, n in pairs(tempTable) do
					if table_c.components[m] == nil or table_c.components[m] ~= n then
						recipeMemory = false
						break
					end
				end
					
				if recipeMemory then
					CRAFTABLE_ITEMS = table_c
					for xex, xec in ipairs(removeTable) do
						doRemoveItem(xec)
					end
					break
				end
			end
		end
	else
		anvilOnPos = true
	end

	CRAFTABLE_ITEMS = (CRAFTABLE_ITEMS == nil) and (getThingFromPos({x = toPosition.x, y = toPosition.y, z = toPosition.z, stackpos = 2}).itemid == 2555 and  ((craftable_table[itemEx.itemid]) ~= nil) and (craftable_table[itemEx.itemid])[itemEx.type]) or (anvilOnPos and CRAFTABLE_ITEMS) or nil

	
	if anvilOnPos then
		if crafting(cid, item, fromPosition, itemEx, toPosition, CRAFTABLE_ITEMS) then
			doCreatureSay(cid, "Stuk!", TALKTYPE_ORANGE_1)
		end
	end
	return true
end